package client.view;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JComponent;

/**
 * ZOrderer is a MouseAdapter extension that brings JComponents to the
 * top of the container that they are held in when they are double-clicked.
 */
public class ZOrderer extends MouseAdapter {
	public void mouseClicked(MouseEvent me) {
		if (me.getClickCount() > 1)
			moveToTop((JComponent)me.getSource());
	}

	/**
	 * Moves the given JComponent to the top of the container in which it is held
	 */
	private void moveToTop(final JComponent c) {
		c.getParent().setComponentZOrder(c,0);
		c.getParent().repaint();
	}
}